<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="|#{customer.systemTitle}-内容管理-友情链接|">图灵谷</title>
<div th:replace="fragments/head_admin">head</div>
<!--/***** 当前页css  start *****/-->
<!--/***** 当前页css  end *****/-->
</head>
<body>
    <div class="layui-layout layui-layout-admin">
        <div th:replace="fragments/nav_admin">导航栏</div>
        <div th:replace="fragments/menu_admin::menu(parent=content,child=friendlink)">菜单栏</div>
        <!--/*******内容*******/-->
        <div class="layui-body">
            <div class="layui-main">
                <!--/***** 面包屑 *****/-->
                <div class="layui-elem-quote" style="margin-top: 10px;">
                    <span class="layui-breadcrumb"> <a><cite>内容管理</cite></a><a th:href="@{/admin/m/ext/friendlink/list.gsp}">友情链接</a><a><cite>列表</cite></a>
                    </span>
                </div>
                <!--/*******操作*******/-->
                <div class="layui-form-item">
                    <blockquote class="layui-elem-quote layui-quote-nm">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <a th:href="@{/admin/m/ext/friendlink/add.gsp}" class="layui-btn"><i class="layui-icon">&#xe61f;</i> 新增</a>
                            </div>
                        </div>
                    </blockquote>
                </div>
                <!--/***** 列表 *****/-->
                <table class="layui-table" lay-even="" lay-skin="row">
                    <thead id="dataTable">
                        <tr>
                            <th style="width: 40px">#</th>
                            <th style="width: 40px">状态</th>
                            <th>是否推荐</th>
                            <th>链接类型</th>
                            <th>链接名称</th>
                            <th>电子邮箱</th>
                            <th>网站地址</th>
                            <th>描述</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr th:if="${friendlinkList.records == null or friendlinkList.records.size() == 0}">
                            <td colspan="9" style="text-align: center;">暂时没有数据</td>
                        </tr>
                        <tr th:each="item,items:${friendlinkList.records}">
                            <td th:text="${friendlinkList.pageSize*(friendlinkList.page-1)+items.index+1}" style="text-align: center;">序号</td>
                            <td class="layui-form"><input lay-filter="filter" th:id="${item.id}" lay-skin="switch" type="checkbox" th:attr="checked=${item.enabled ==1}"></td>
                            <td th:text="${item.recommend==1?'是':'否'}">是否推荐</td>
                            <td th:text="${item.typeName}">链接类型</td>
                            <td th:text="${item.flName}">链接名称</td>
                            <td th:text="${item.flEmail}">电子邮箱</td>
                            <td th:text="${item.flUrl}">网站地址</td>
                            <td th:text="${item.description}">描述</td>
                            <td style="text-align: center;"><a class="layui-btn layui-btn-small" th:href="@{/admin/m/ext/friendlink/edit_{id}.gsp(id=${item.id})}"><i
                                    class="layui-icon">&#xe642;</i></a>
                                <button class="layui-btn layui-btn-small layui-btn-normal" th:onclick="|deleted('${item.id}')|">
                                    <i class="layui-icon">&#xe640;</i>
                                </button></td>
                        </tr>
                    </tbody>
                </table>
                <div id="pageDiv"></div>
            </div>
        </div>
        <div th:replace="fragments/footer_admin">底部版权信息等</div>
    </div>
</body>
<div th:replace="fragments/import_js_admin">引入js</div>
<!--/***** 当前页js start *****/-->
<script th:inline="javascript">
    /*<![CDATA[*/
    var form = layui.form();
    var enableUrl = /*[[@{/admin/m/ext/friendlink/enable_{id}.gsp}]]*/;
    var disableUrl = /*[[@{/admin/m/ext/friendlink/disable_{id}.gsp}]]*/;
    form.on('switch(filter)', function(data){
        var id = data.elem.id;
        if(!$("#" + data.elem.id).prop("checked")){  
            layer.confirm('您确定要停用吗？', {
                btn: ['确定','取消'] 
            }, function(){
             //停用
             var url = disableUrl.replace("{id}",data.elem.id);
             $.post(url,{'id':data.elem.id},function(){    
                 $("#" + data.elem.id).prop("checked", false);
                 $("#" + data.elem.id).next().removeClass("layui-form-onswitch");
             });  
             layer.msg('停用成功！', {icon: 1});
             setTimeout(function(){window.location.reload();},1000);
            }, function(){
                $("#" + data.elem.id).prop("checked", true);
                $("#" + data.elem.id).next().addClass("layui-form-onswitch");
            });
        }else if($("#" + data.elem.id).prop("checked")){   
            layer.confirm('您确定要启用吗？', {
                btn: ['确定','取消'] 
            }, function(){
          //启用
          var url = enableUrl.replace("{id}",data.elem.id);
          $.post(url,{'id':data.elem.id},function(){
              $("#" + data.elem.id).prop("checked", true);
              $("#" + data.elem.id).next().addClass("layui-form-onswitch");
          });
          layer.msg('启用成功！', {icon: 1});
          setTimeout(function(){window.location.reload();},1000);
          }, function(){
              $("#" + data.elem.id).prop("checked", false);
              $("#" + data.elem.id).next().removeClass("layui-form-onswitch");
          });
        }    
    });  
    var result = /*[[${friendlinkList}]]*/;
    $(function(){
        var option = {
            listUrl : /*[[@{/admin/m/ext/friendlink/list.gsp?}]]*/,
            totalPages : result.totalPages,
            page : result.page,
            param : {
            }
        };
        tg_basePage(option);
    })

    var deleteUrl = /*[[@{/admin/m/ext/friendlink/delete_{id}.gsp}]]*/;
    function deleted(id) {
        tg_deleteItem(deleteUrl.replace('{id}',id), function(){
            location.reload();
        });
    }
    /*]]>*/
</script>
<!--/***** 当前页js end *****/-->
</html>